<template>
  <el-form ref="formRef" :model="form" label-width="120px" size="default">
    <el-form-item>
      <h2>
        <el-link type="warning">按身份证标异常</el-link>
      </h2>
    </el-form-item>
    <el-form-item label="身份证号：">
      <el-input v-model="form.cardNumber" clearable class="input-width"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="add">添加</el-button>
      <el-button type="danger" @click="reset">重置</el-button>
    </el-form-item>
    <el-form-item label="">
      {{ JSON.stringify(form.cardNumbers) }}
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">生成脚本</el-button>
      <el-button type="default" @click="exportFile">导出文件</el-button>
    </el-form-item>
    <el-form-item label="脚本：">
      <el-input autosize type="textarea" v-model="form.scriptString" readonly></el-input>
    </el-form-item>
  </el-form>
</template>

<script setup>
import { reactive } from "vue";
import saveAs from "./js/FileSaver";
// do not use same name with ref
const form = reactive({
  // 身份证号
  cardNumber: "",
  // 审核人数组
  cardNumbers: [],
  // 脚本
  scriptString: ""
});

const add = () => {
  form.cardNumber.trim() ? form.cardNumbers.push(form.cardNumber.trim()) : "";
  form.cardNumber = "";
};

const reset = () => {
  form.cardNumber = "";
  form.cardNumbers = [];
};

const exportFile = () => {
  let str = new Blob([form.scriptString], {
    type: "text/plain;charset=utf-8"
  });
  saveAs(str, `按身份证标异常.txt`);
};

const onSubmit = () => {
  form.scriptString = `环境：太极政务云
数据库地址：192.159.107.33:2000
数据库名：nat_admin
预计影响数据量：nat_appo_check，nat_appo_check_relation共计${
    form.cardNumbers.length ? form.cardNumbers.length * 2 : "0"
  }条

先备份：（请将备份的数据写在jira的备注里，如果数据多，可以生成txt文件上传到jira里）
var c = db.nat_appo_check.find(
{"checked_person_card_number":{"$in":${JSON.stringify(form.cardNumbers)}},"status":{"$nin":[4,5,6]}}
)
d = []
while(c.hasNext()) {
d.push(c.next())
}
printjson(d)

var c = db.nat_appo_check_relation.find({"checked_person_card_number":{"$in":
${JSON.stringify(form.cardNumbers)}
},"status":{"$nin":[4,5,6]}})
d = []
while(c.hasNext()) {
d.push(c.next())
}
printjson(d)


先标记异常，再将print出来的语句在redis执行（如果没有打印就不用在redis执行）：
db.nat_appo_check.find({"checked_person_card_number":{"$in":
${JSON.stringify(form.cardNumbers)}
},"status":{"$nin":[4,5,6]}}).forEach(function(document){
db.nat_appo_check.update({"id":{"$in":[document.id]}},{"$set":{"abnormal_sign": NumberInt(1),"status":NumberInt(5),"update_abnormal_by":"admin_manual_abnormal"}},false,true);
db.nat_appo_check_relation.update({"id":{"$in":[document.id]}},{"$set":{"abnormal_sign": NumberInt(1),"appo_status":NumberInt(5),"update_abnormal_by":"admin_manual_abnormal"}},false,true);
print("del appointment."+document.appo_person);
print("del appointment."+document.appo_unique_code);
})`;
};
</script>

<style>
.input-width {
  width: 500px;
}
</style>
